// xc_lshop/shop/user/warehouse/record.js
var actbill = require('../../../../xc/model/user_warehouse')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    navid: 0,
    navkey:{
      1:"商品购买",
      2:"官网托售",
      4:"官网回收",
      8:"托售成功",
      16:"商品发货",
      32:"取消托售",
    },
    nav: [{
        id: 0,
        name: "全部"
      },
      {
        id: 1,
        name: "购买记录"
      },
      {
        id: 42,
        name: "托售记录"
      },
      {
        id: 4,
        name: "回收记录"
      },
      // {
      //   id: 8,
      //   name: "成交记录"
      // },
      {
        id: 16,
        name: "发货记录"
      },
      // {
      //   id: 32,
      //   name: "取消托售"
      // },
    ],
    proid:0
  },
  xcloaddata: function (options, config) {
    var update = {};
    // console.log("config")
    // console.log(config)

    if (options.proid) {
      update["proid"] = options.proid
    }
    this.setData(update)
    var that=this;
    this.getpagelist(that, 1)

  },
  onChangeNav(e) {
     this.setData({
      navid:e.detail.name
     })
     var that=this;
    this.getpagelist(that, 1)
  },
  getpagelist(that, rest, strwhere) {
    if (rest == 1) {
      if (!strwhere) {
        strwhere = {};
      }
      strwhere["status"] = 1;
      strwhere["type"] = this.data.navid;

      strwhere["proid"] = this.data.proid;
      // strwhere["spid"] = this.data.actspid;
      // strwhere["seachval"] = this.data.seachval;
      that.setData({
        modellist: [],
        loadinglist: true
      });
    }
    actbill.recordoffset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};

      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {

        // var modellist=result["obj"]["modellist"];
        // for(var i in modellist){
        //   for
        // }
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      console.log(updatemdoel)
      wx.stopPullDownRefresh();
      updatemdoel['loadinglist'] = false
      that.setData(updatemdoel);
      // that.selectComponent("#choose").init(updatemdoel["modellist"][0],"recovery")

    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    this.getpagelist(that, -1)
  },
})